package com.example.lsrsbackend.model;

import jakarta.persistence.*;
import com.fasterxml.jackson.annotation.JsonFormat;

import java.sql.Time;
import java.util.Date;

@Entity
@Table(name = "reservations")
public class Reservation {

    //枚举类
    /*
    PENDING_FULFILLMENT：待履约状态，用户已预约但尚未使用座位
    FULFILLED：已履约状态，用户已完成座位使用
    CANCELLED：已取消状态，用户主动取消了预约
    BREACH：违约状态，用户未按约定使用座位
    */
    public enum Status {
        pending_fulfillment, fulfilled, cancelled, breach
    }


    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false,name="seat_id")
    private Long seatId;

    @Column(nullable = false,name="username")
    private String  username;

    @Column(nullable = false)
    private Date date;

    @Column(nullable = false,name="start_time")
    private Time startTime;

    @Column(nullable = false,name="end_time")
    private Time endTime;

    @Column(nullable = false, precision = 3,name="duration_hours")
    private Double durationHours;



    @Enumerated(EnumType.STRING)
    private Status status = Status.pending_fulfillment;

    @Column(name = "actual_checkin_time")
    private Date actualCheckinTime;

    @Column(name = "actual_checkout_time")
    private Date actualCheckoutTime;


    @Column(nullable = false, columnDefinition = "int default 0",name = "extend_count")
    //作用：columnDefinition 允许你指定完整的SQL列定义，包括数据类型和默认值
    private Integer extendCount = 0;

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "created_at")
    private Date createdAt;

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "updated_at")
    private Date updatedAt;

    // Getters and Setters

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getSeatId() {
        return seatId;
    }

    public void setSeatId(Long seatId) {
        this.seatId = seatId;
    }



    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public Time getStartTime() {
        return startTime;
    }

    public void setStartTime(Time startTime) {
        this.startTime = startTime;
    }

    public Time getEndTime() {
        return endTime;
    }

    public void setEndTime(Time endTime) {
        this.endTime = endTime;
    }

    public Double getDurationHours() {
        return durationHours;
    }

    public void setDurationHours(Double durationHours) {
        this.durationHours = durationHours;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public Date getActualCheckinTime() {
        return actualCheckinTime;
    }

    public void setActualCheckinTime(Date actualCheckinTime) {
        this.actualCheckinTime = actualCheckinTime;
    }

    public Date getActualCheckoutTime() {
        return actualCheckoutTime;
    }

    public void setActualCheckoutTime(Date actualCheckoutTime) {
        this.actualCheckoutTime = actualCheckoutTime;
    }

    public Integer getExtendCount() {
        return extendCount;
    }

    public void setExtendCount(Integer extendCount) {
        this.extendCount = extendCount;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public Date getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Date updatedAt) {
        this.updatedAt = updatedAt;
    }

    public String  getUsername() {
        return username;
    }

    public void setUsername(String  username) {
        this.username = username;
    }
}